/*
 * BanBu_FullScreenCell
 * @description 本文件提供聊天界面对话界面显示全屏播放gif动画消息的cell
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供聊天界面对话界面显示全屏播放gif动画消息的cell
 */

#import "BanBu_FullScreenCell.h"
#import "BanBuAPIs.h"
#import "AppDataManager.h"
#import "AppCommunicationManager.h"


@implementation BanBu_FullScreenCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        //网页
        _fullGifView = [[BanBu_FullScreenGIF alloc]initWithFrame:CGRectZero];
        _fullGifView.backgroundColor = [UIColor clearColor];
        [self addSubview:_fullGifView];
        
        _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [_activityIndicator setFrame:CGRectMake(0, 17, 30, 30)];
        _activityIndicator.center = self.bkView.center;
        [_activityIndicator setHidesWhenStopped:YES];
        [_activityIndicator setColor:[UIColor blackColor]];
        
        [_activityIndicator  startAnimating];
        [self addSubview:_activityIndicator];
    }
    return self;
}

-(void)dealloc
{
    [_activityIndicator release],_activityIndicator = nil;
    [_fullGifView release],_fullGifView = nil;
    
    [super dealloc];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    float height = self.contentView.frame.size.height;
    
    self.bkView.alpha = 0;
    self.bkView.frame = BKViewRect00(self.bkViewWidth, height-5);
    
    _fullGifView.frame=MediaViewRect00;
        
    [_fullGifView setimageFrame:MediaViewRect00];
    
    self.bkView.bounds = CGRectMake(0, 0, self.bkView.frame.size.width, self.bkView.frame.size.height-10);
    
    if (self.atLeft)
    {
        _fullGifView.frame = CGRectMake(_fullGifView.frame.origin.x-10, _fullGifView.frame.origin.y,_fullGifView.frame.size.width,_fullGifView.frame.size.height);
    }
    else
    {
        _fullGifView.frame = CGRectMake(_fullGifView.frame.origin.x+15, _fullGifView.frame.origin.y,_fullGifView.frame.size.width,_fullGifView.frame.size.height);
        CGRect frame = self.statusView.frame;
        frame.origin.x += 20;
        self.statusView.frame = frame;
    }
    self.activityIndicator.center = _fullGifView.center;
    
    
    if (self.showFrom)
    {
        [self setShowFromFrame:ChatMsgMediaView];
    }
    self.avatar.frame = AvatarRect01;
//    [self.vipImageView setFrame:CGRectMake(self.avatar.frame.origin.x + 28, self.avatar.frame.origin.y + 26, 15, 10)];
}

-(void)setMsgMediastatus:(MediaStatus)status
{
    if(status != MediaStatusNormal && status != MediaStatusReaded)//不是：已播过或正常时，loading转圈
    {
        [self.activityIndicator  startAnimating];
    }
    else
    {
        [self.activityIndicator  stopAnimating];
    }
}

//设置cell的各种信息
-(void)setChatCellInfo:(NSDictionary *)amsg
{
    self.bkViewWidth = 90.0;
    [super setChatCellInfo:amsg];
    
    self.showFrom  = YES;
    
    _fullGifView.atLift = self.atLeft;
    
    MediaStatus status = [VALUE(KeyMediaStatus, amsg) integerValue];
    _fullGifView.statusNow = status;
    _fullGifView.chatid = [amsg valueForKey:KeyChatid];
    
    NSString * content = VALUE(KeyContent, amsg);
    NSString * thumbnail = VALUE(KeyThumbnail, amsg);
    
    if(thumbnail&&thumbnail.length)
        [_fullGifView setMediaGIFPath:thumbnail];
    
    [_fullGifView setImagePath:content];
    [_fullGifView setStatus:status];
    
    if (status == MediaStatusDownload)
    {//下载
        [AppComManager getBanBuMagicGifMedia:content forMsgID:VALUE(KeyChatid, amsg) fromUid:MyAppDataManager.chatuid delegate:MyAppDataManager];
        [AppComManager getBanBuMediaMagicThumbnail:thumbnail forMsgID:VALUE(KeyChatid, amsg) fromUid:MyAppDataManager.chatuid delegate:MyAppDataManager];
    }
    
    [self setMsgMediastatus:status];
}

@end
